package com.sri.business.user;

import java.sql.SQLException;
import java.util.Date;

import com.sri.db.dao.user.UserDAO;
import com.sri.db.dao.user.UserDAOServiceFactory;
import com.sri.formBeans.NewUserForm;
import com.sri.model.user.User;

public class UserManager {
	private UserManager() {
	}

	public static boolean addUser(NewUserForm form)  {
		System.out.println("UserManager-addUser");
		boolean added = false;
		UserDAO userDAO = UserDAOServiceFactory.getUserDAO();
		try {
			added = userDAO.addUser(populateUser(form));
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return added;
	}

	private static User populateUser(NewUserForm form) {
		User user = new User();
		user.setName(form.getUserFullName());
		user.setMailId(form.getEmail());
		user.setUserName(form.getUserName());
		user.setPassWord(form.getPassword());
		user.setMobile(form.getMobile());
		user.setHouseNo(form.getHouseNo());
		user.setStreet(form.getStreet());
		user.setCity(form.getCity());
		user.setState(form.getState());
		user.setZipCode(form.getZipCode());
		user.setLoginMailId(form.getLoginEmail());
		user.setCreatedDate(new Date());
		user.setProfession(form.getProfession());
		user.setType(form.getUserType());
		user.setGender((form.isGender()) ? "1" : "0");
		return user;
	}

}
